# -*- coding: utf-8 -*-
import unittest
import sys
import os
import time

# 添加执行环境
file_exec_path = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
sys.path.insert(0, file_exec_path)
from framework_strategy.gopy.trader.engine import EmailEngine, MainEngine, EventEngine  # NOQA

# init


def init_engine():
    eeg = EventEngine()

    mg = MainEngine(eeg)
    ea = EmailEngine(mg, eeg)
    return ea, mg


# 测试邮箱发送
class TestEamilEngine(unittest.TestCase):

    @unittest.skip
    def test_send_email(self):

        email_engine, _ = init_engine()
        email_engine.start()
        print("[*] send email...")

        subject = "Test Email"
        content = "测试邮件发送"
        email_engine.send_email(subject, content)
        print("[*] send email over...")

        time.sleep(1)
        email_engine.close()
        print("[*] send process over...")

    # @unittest.skip
    def test_main_send_email(self):

        email_engine, mg = init_engine()
        print("[*] send email...")

        subject = "<Test Email>"
        content = "测试邮件发送 111"
        mg.send_email(subject, content)
        print("[*] send email over...")

        time.sleep(1)
        email_engine.close()
        print("[*] send process over...")


if __name__ == "__main__":
    unittest.main()
